package xerr

import "fmt"

type Error struct {
	code uint32
	msg  string
}

func (e *Error) GetCode() uint32 {
	return e.code
}

func (e *Error) GetMsg() string {
	return e.msg
}

// 实现error接口
func (e *Error) Error() string {
	return fmt.Sprintf("errCode: %d,errMsg: %s", e.code, e.msg)
}

func NewError(code uint32, msg string) *Error {
	return &Error{
		code: code,
		msg:  msg,
	}
}

func NewErrorWithCode(code uint32) *Error {
	return &Error{
		code: code,
		msg:  GetMsgByCode(code),
	}
}

func NewErrorWithMsg(msg string) *Error {
	return &Error{
		code: ServerError,
		msg:  msg,
	}
}
